package com.dingshi.security.api;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.dingshi.security.config.HttpClientConfig;
import com.dingshi.security.entity.ShiftChange;
import com.dingshi.security.net.HttpResult;
import com.dingshi.security.net.HttpResultJson;
import com.dingshi.security.net.NetService;

public class ShiftChangeApi extends BaseApi {

	protected static final String TAG = "DialApi";

	public ShiftChangeApi(Context context) {
		super(context);
	}

	public void getShiftList(final int requestCode, final String did,final Context context){
	
		
		
		new AsyncTask<Object, Integer, ApiResult<Object>>() {
			@Override
			protected ApiResult<Object> doInBackground(Object... strs) {
				JSONObject obj = new JSONObject();
				try {
					obj.put("did", did);
				} catch (JSONException e2) {
					e2.printStackTrace();
				}
				Log.e(TAG, "request params "+obj.toString());
				ApiResult<Object> apiResult = new ApiResult<Object>();
				apiResult.setResultCode(ApiResult.RESULT_FAIL);
				HttpResultJson result = NetService.getWebServices(obj.toString(),context,HttpClientConfig.GET_SHIFT_LIST);
				if (result.getResultCode() == HttpResult.RESULT_OK) {
					apiResult.setResultCode(ApiResult.RESULT_OK);
					JSONObject json = result.getJson();
					apiResult.setJsonEntity(json);

				} else {
					apiResult.setFailCode(result.getFailCode());
					apiResult.setFailMessage(result.getFailMessage());
				}
				return apiResult;
			}

			@Override
			protected void onPostExecute(ApiResult<Object> apiResult) {
				if (returnResultListener == null) {
					return;
				}
				if (apiResult.getResultCode() == ApiResult.RESULT_OK) {
					returnResultListener.onReturnSucceedResult(requestCode,
							apiResult);
				} else {
					returnResultListener.onReturnFailResult(requestCode,
							apiResult);
				}
			}

			@Override
			protected void onPreExecute() {
				if (returnResultListener == null) {
					return;
				}
					returnResultListener.onReturnLoading(requestCode);
				super.onPreExecute();
			}
			
			
			
		}.execute("");
	}
	
	public void shiftChange(final int requestCode, final Context context,final ShiftChange shift){



		new AsyncTask<Object, Integer, ApiResult<Object>>() {
			@Override
			protected ApiResult<Object> doInBackground(Object... strs) {
				JSONObject obj = new JSONObject();
				try {
					obj.put("did", shift.getDid());
					obj.put("aid", shift.getAid());
					obj.put("nid1", shift.getNid1());
					obj.put("nid2", shift.getNid2());
					obj.put("s1", shift.getS1());
					obj.put("s2", shift.getS2());
					obj.put("s3", shift.getS3());
					obj.put("log", shift.getLog());
				} catch (JSONException e2) {
					e2.printStackTrace();
				}
				Log.e(TAG, "request params "+obj.toString());
				ApiResult<Object> apiResult = new ApiResult<Object>();
				apiResult.setResultCode(ApiResult.RESULT_FAIL);
				HttpResultJson result = NetService.getWebServices(obj.toString(),context,HttpClientConfig.SHIFT_CHANGE_URL);
				if (result.getResultCode() == HttpResult.RESULT_OK) {
					apiResult.setResultCode(ApiResult.RESULT_OK);
					JSONObject json = result.getJson();
					apiResult.setJsonEntity(json);

				} else {
					apiResult.setFailCode(result.getFailCode());
					apiResult.setFailMessage(result.getFailMessage());
				}
				return apiResult;
			}

			@Override
			protected void onPostExecute(ApiResult<Object> apiResult) {
				if (returnResultListener == null) {
					return;
				}
				if (apiResult.getResultCode() == ApiResult.RESULT_OK) {
					returnResultListener.onReturnSucceedResult(requestCode,
							apiResult);
				} else {
					returnResultListener.onReturnFailResult(requestCode,
							apiResult);
				}
			}

			@Override
			protected void onPreExecute() {
				if (returnResultListener == null) {
					return;
				}
				returnResultListener.onReturnLoading(requestCode);
				super.onPreExecute();
			}



		}.execute("");
	}
}
